<?php
namespace asyncService;

use asyncService\lib\log;

/**
 * Class Bootstrap
 * @property static $Log
 * @package asyncService
 */
class Bootstrap
{
    /**
     * @var Bootstrap
     */
    static $instance = false;

    static function newInstance($config){
        self::$instance  = new static($config);
    }

    static function getInstance(){
        if(!self::$instance){
            throw  new \Exception("Bootstrap not instance !");
        }
        return self::$instance;
    }

    protected $config;

    static function __callStatic($name, $arguments)
    {
        $instance = self::getInstance()->getInstance();
        $method = "get$name";
        if(method_exists($instance,$method)){
            return call_user_func_array(array($instance,$method),$arguments);
        }
    }

    public function __construct($config)
    {
        $this->config = $config;

        $this->handle();
    }

    public function handle(){

    }

    public function getLog(){
        return log::getInstance("main");
    }


    /**
     * 获取配置项目
     * @param $key
     * @return array
     */
    public function getConfig($key){
        if(!isset($this->config[$key])){
            return [];
        }
        return $this->config[$key];
    }

}